﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Collections.Generic;

namespace Final_Project
{
    class CXmlConfigReader
    {
        static private CXmlConfigReader m_sPtr = null;
        private Dictionary<string, string> Dict;

        private CXmlConfigReader()
        {
            string strName = "", strValue = "";
            XmlTextReader reader = new XmlTextReader("Config.xml");
            Dict = new Dictionary<string,string>();

            while(reader.Read())
            {
                switch(reader.NodeType)
                {
                    case XmlNodeType.Element:
                        strName = reader.Name;
                        break;
                    case XmlNodeType.Text:
                        strValue = reader.Value;
                        Dict.Add(strName,strValue);
                        break;
                    default:
                        break;
                }
            }
        }

        static public CXmlConfigReader Instance()
        {
            if (null == m_sPtr)
            {
                m_sPtr = new CXmlConfigReader();
                return m_sPtr;
            }
            return m_sPtr;
        }

        public string ReadValueFromElement(string strElement)
        {
            return Dict[strElement];
        }
    }
}
